package com.example.cms.controller;

import com.example.cms.entity.Customer;
import com.example.cms.pojo.FileExport;
import com.example.cms.pojo.QueryPage;
import com.example.cms.service.CustomerService;
import com.example.cms.until.ExcelUtil1;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ClassName EcexlExprotController
 * @Descriptiom excel 文件导出
 * @Author Sunbird
 * @Date 2018/12/17 9:09
 * @Version 1.0
 **/
@Controller
public class EcexlExprotController {
        @Autowired
        private CustomerService customerService;
    @RequestMapping("ExportCustomer")
    public void ExcelExprot(HttpServletRequest request, HttpServletResponse response, QueryPage queryPage) throws Exception {
        request.setCharacterEncoding("UTF-8");
        response.setHeader("content-Type", "application/vnd.ms-excel");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=customer.xls");
        FileExport data = customerService.exportUserDTO(queryPage);
        SimpleDateFormat fdate=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
        String fileName="客户信息"+fdate.format(new Date())+".xls";
        ExcelUtil1.exportExcel(response, fileName, data);
    }
}
